Restart session either by using GUI Session > Restart R or by Ctrl + Shift + F10. You should start with empty “Environment”. Tip: you can also clear your R console with Ctrl + L.
Load packages:
if (!require("tidyverse")) install.packages("tidyverse"); library("tidyverse")
if (!require("sf")) install.packages("sf"); library("sf")
if (!require("tmap")) install.packages("tmap"); library("tmap")
if (!require("sjmisc")) install.packages("sjmisc"); library("sjmisc")Load data prepared during previous session:
SA2_SEIFA <- readRDS("data/SA2_SEIFA.Rds")We already use quck map qtm functionality of tmap library. We will extend its use by providing additional argument from linked SEIFA data:
tmap_mode("view")## tmap mode set to interactive viewing
SA2_SEIFA %>%
qtm(fill = "IRSAD_d")We get one more map of SA2s. This time it’s a thematic map! We mapped IRSAD_d variable to assign a colour that will fill polygon of SA2 using its particular value of decile.
Making quick maps can quickly become cumbersome when more options need to be specified to improve the map. We will switch to building maps layer by layer, similarly to ggplot package. Lets rewrite the code using more advanced syntax of tmap. We first define our base map using tm_shape function and then instruct tmap to treat it as layers of polygons with certain attributes:
tm_shape(SA2_SEIFA) +
tm_polygons(col = "IRSAD_d",
n = 10, alpha = 0.7, palette = "RdYlGn", lwd = 0)Can you guess what the parameters of tm_polygons are? Use help(tm_polygons) to learn about the one that you don’t know. Try changing a colour scheme of your map. Running code tmaptools::palette_explorer() will help guide your choices.
tm_facets
tm_shape(SA2_SEIFA) +
tm_polygons(col = c("IRSAD_d", "IER_d"),
n = 10, alpha = 0.7, palette = "RdYlGn", lwd = 0) +
tm_facets(sync = TRUE, ncol = 2)